/*
 * This class creates the program to test the banking classes.
 * It creates a new Bank, sets the Customer (with an initial balance),
 * and performs a series of transactions with the Account object.
 */

import banking.*;

public class TestBanking05 {

  public static void main(String[] args) {
    Bank     bank = new Bank();
    Customer customer;
    Account account;



    //
    // Create bank customers and their accounts
    // 创建银行客户及其账户
    //

    System.out.println("Creating the customer Jane Smith.");
    // 创建客户 Jane Smith
    bank.addCustomer("Jane", "Simms");
    //code
    System.out.println("Creating her Savings Account with a 500.00 balance and 3% interest.");
    // 创建她的储蓄账户，余额为 500.00，利息为 3%。
    customer = bank.getCustomer(0);
    customer.setAccount(new SavingAccount(500.00, 0.03));
    //code


    System.out.println("Creating the customer Owen Bryant.");
    // 创建客户 Owen Bryant
    bank.addCustomer("Owen", "Bryant");
    customer = bank.getCustomer(1);
    System.out.println("Creating his Checking Account with a 500.00 balance and no overdraft protection.");
    // 创建余额为 500.00 且无透支保护的支票账户。
    customer.setAccount(new CheckingAccount(500.00));



    //code
    System.out.println("Creating the customer Tim Soley.");
    // 创建客户 Tim Soley。
    bank.addCustomer("Tim", "Soley");
    customer = bank.getCustomer(2);
    System.out.println("Creating his Checking Account with a 500.00 balance and 500.00 in overdraft protection.");
    // 创建具有 500.00 余额和 500.00 透支保护的支票帐户。
    customer.setAccount(new CheckingAccount(500.00, 500.00));

    //code
    System.out.println("Creating the customer Maria Soley.");
    //code
    // 创建客户 Maria Soley
    bank.addCustomer("Maria", "Soley");
    customer = bank.getCustomer(3);
    System.out.println("Maria shares her Checking Account with her husband Tim.");
    // Maria 与她的丈夫 Tim 共享她的支票账户。
    customer.setAccount(bank.getCustomer(2).getAccount());

    System.out.println();

    //
    // Demonstrate behavior of various account types
    // 演示各种帐户类型的行为
    //

    // Test a standard Savings Account
    // 测试标准储蓄帐户
    System.out.println("Retrieving the customer Jane Smith with her savings account.");
    // 检索 Jane Smith 的客户及其储蓄帐户。
    customer = bank.getCustomer(0);
    account = customer.getAccount();
    // Perform some account transactions
    System.out.println("Withdraw 150.00: " + account.withdraw(150.00));
    System.out.println("Deposit 22.50: " + account.deposit(22.50));
    System.out.println("Withdraw 47.62: " + account.withdraw(47.62));
    System.out.println("Withdraw 400.00: " + account.withdraw(400.00));
    // Print out the final account balance
    System.out.println("Customer [" + customer.getLastName()
            + ", " + customer.getFirstName()
            + "] has a balance of " + account.getBalance());

    System.out.println();

    // Test a Checking Account w/o overdraft protection
    // 不带透支保护的支票帐户
    System.out.println("Retrieving the customer Owen Bryant with his checking account with no overdraft protection.");
    // 检索 Owen Bryant 的客户及其支票帐户。
    customer = bank.getCustomer(1);
    account = (CheckingAccount)customer.getAccount();

    // Perform some account transactions
    System.out.println("Withdraw 150.00: " + account.withdraw(150.00));
    System.out.println("Deposit 22.50: " + account.deposit(22.50));
    System.out.println("Withdraw 47.62: " + account.withdraw(47.62));
    // 调用的是Account子类CheckingAccount的withdraw方法 而不是 Account的方法



    System.out.println("Withdraw 400.00: " + account.withdraw(400.00));
    // Print out the final account balance
    System.out.println("Customer [" + customer.getLastName()
            + ", " + customer.getFirstName()
            + "] has a balance of " + account.getBalance());

    System.out.println();

    // Test a Checking Account with overdraft protection
    // 有透支保护的支票帐户
    System.out.println("Retrieving the customer Tim Soley with his checking account that has overdraft protection.");
    // 检索 Tim Soley 的客户及其支票帐户。
    customer = bank.getCustomer(2);
    account = customer.getAccount();
    // Perform some account transactions
    System.out.println("Withdraw 150.00: " + account.withdraw(150.00));
    System.out.println("Deposit 22.50: " + account.deposit(22.50));
    System.out.println("Withdraw 47.62: " + account.withdraw(47.62));
    System.out.println("Withdraw 400.00: " + account.withdraw(400.00));
    // Print out the final account balance
    System.out.println("Customer [" + customer.getLastName()
            + ", " + customer.getFirstName()
            + "] has a balance of " + account.getBalance());

    System.out.println();

    // Test a Checking Account with overdraft protection
    // 有透支保护的支票帐户
    System.out.println("Retrieving the customer Maria Soley with her joint checking account with husband Tim.");
    // 检索 Maria Soley 的客户及其支票帐户。
    customer = bank.getCustomer(3);
    account = customer.getAccount();
    // Perform some account transactions
    System.out.println("Deposit 150.00: " + account.deposit(150.00));
    System.out.println(account.getBalance());
    System.out.println("Withdraw 750.00: " + account.withdraw(750.00));
    // Print out the final account balance
    System.out.println("Customer [" + customer.getLastName()
            + ", " + customer.getFirstName()
            + "] has a balance of " + account.getBalance());

  }
}
